package gov.ccswj.modules.app.service.impl;


import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import gov.ccswj.modules.app.dao.DomesticInvestmentDao;
import gov.ccswj.modules.app.entity.DomesticInvestmentEntity;
import gov.ccswj.modules.app.entity.GeneralEntity;
import gov.ccswj.modules.app.entity.GeneralEntity2;
import gov.ccswj.modules.app.entity.GeneralEntity3;
import gov.ccswj.modules.app.entity.GeneralEntity4;
import gov.ccswj.modules.app.service.DomesticInvestmentService;



@Service("domesticInvestmentService")
public class DomesticInvestmentServiceImpl implements DomesticInvestmentService {
	@Autowired
	private DomesticInvestmentDao domesticInvestmentDao;

    /**
     * 重载方法
     * @return
     */
    @Override
    public DomesticInvestmentEntity getDomesticInvestment() {
        
        return domesticInvestmentDao.queryObject(null);
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public List<GeneralEntity> getNztzlyzb1() {
        return domesticInvestmentDao.getNztzlyzb1();
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public List<GeneralEntity3> getNztzlyzb2() {
        List<GeneralEntity3> arr1 = domesticInvestmentDao.getNztzlyzb2();
        List<GeneralEntity3> arr2 = domesticInvestmentDao.getNztzlyzb4();
        List<GeneralEntity3> arr3 = domesticInvestmentDao.getNztzlyzb5();
        arr1.addAll(arr2);
        arr1.addAll(arr3);
        return arr1;
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public List<GeneralEntity> getNztzlyzb3() {
        return domesticInvestmentDao.getNztzlyzb3();
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public List<GeneralEntity> getNztzgm() {
        return domesticInvestmentDao.getNztzgm();
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public Map getNzzjly() {
        Map res = new LinkedHashMap<>();
        Map res1 = new LinkedHashMap<>();
        List<GeneralEntity> lynzyjqk2 = domesticInvestmentDao.getNzzjly();
        for (GeneralEntity generalEntity : lynzyjqk2) {
            res1.put(generalEntity.getName(), generalEntity.getValue());
        }
        res.put("total", domesticInvestmentDao.getNzzjlyTotal());
        res.put("charts", res1);
        return res;
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public GeneralEntity2 getLynzyjqk1() {
        return domesticInvestmentDao.getLynzyjqk1();
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public Map getLynzyjqk2() {
        Map res = new LinkedHashMap<>();
        Map res1 = new LinkedHashMap<>();
        List<GeneralEntity> lynzyjqk2 = domesticInvestmentDao.getLynzyjqk2();
        for (GeneralEntity generalEntity : lynzyjqk2) {
            res1.put(generalEntity.getName(), generalEntity.getValue());
        }
        res.put("amount", res1);
        res.put("color", getColor(lynzyjqk2));
        return res;
    }
    
    public Map getColor(List<GeneralEntity> data){
        Map res = new LinkedHashMap<>();
        String[] bArray = {"#60b1f7","#bdd5ed","#2e7ded", "#9ecbfb", "#aad2fb", "#3084ee", "#1444da", "#bed5ed", "#71c3fa", "#60b1f7"};
        for (int i = 0; i < bArray.length; i++) {
            res.put(data.get(i).getName(), bArray[i]);
        }
        return res;
    }
    
    /**
     * 重载方法
     * @return
     */
    @Override
    public GeneralEntity2 getLywzyjqk1() {
        return domesticInvestmentDao.getLywzyjqk1();
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public Map getLywzyjqk2() {
        Map res = new LinkedHashMap<>();
        Map res1 = new LinkedHashMap<>();
        List<GeneralEntity> lynzyjqk2 = domesticInvestmentDao.getLywzyjqk2();
        for (GeneralEntity generalEntity : lynzyjqk2) {
            res1.put(generalEntity.getName(), generalEntity.getValue());
        }
        res.put("amount", res1);
        res.put("color", getColor(lynzyjqk2));
        return res;
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public Map getRight2Plate() {
        Map res = new LinkedHashMap();
        res.put("xslszqybx_current", domesticInvestmentDao.getXslszqybx1());
        res.put("xslszqybx_cumulative1", domesticInvestmentDao.getXslszqybx2());
        res.put("wztzze_current", domesticInvestmentDao.getWztzze1());
        res.put("wztzze_cumulative1", domesticInvestmentDao.getWztzze2());
        res.put("gtlywzje_current", domesticInvestmentDao.getGtlywzje1());
        res.put("gtlywzje_cumulative1", domesticInvestmentDao.getGtlywzje2());
        return res;
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public Map getSjlywzje() {
        Map res = new LinkedHashMap();
        res.put("direct_current", domesticInvestmentDao.getSjlywzje1());
        res.put("indirect_current", domesticInvestmentDao.getSjlywzje2());
        return res;
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public List<GeneralEntity> getHtwztop5() {
        return domesticInvestmentDao.getHtwztop5();
    }

    /**
     * 重载方法
     * @return
     */
    @Override
    public List<GeneralEntity4> getXpwzqyzb() {
        List<GeneralEntity4> res = new ArrayList<GeneralEntity4>();
        
        List<GeneralEntity> datas =  domesticInvestmentDao.getXpwzqyzb();
        for (GeneralEntity generalEntity : datas) {
            GeneralEntity4 r1 = new GeneralEntity4();
            r1.setName(generalEntity.getName());
            String[] d = {generalEntity.getValue(),generalEntity.getValue1(),generalEntity.getValue2()};
            r1.setData(d);
            res.add(r1);
        }
        
        return res;
    }
	
}
